#include "SingleJieba.hh"

using namespace cppjieba;

SingleJieba* SingleJieba::_instance = nullptr;


SingleJieba* SingleJieba::createJieba(){
    if(_instance == nullptr){
        _instance = new SingleJieba();
    }
    return _instance;
}

void SingleJieba::destroyJieba(){
    if(_instance != nullptr){
        delete _instance;
        _instance = nullptr;
    }
}

Jieba* SingleJieba::getJieba(){
    return _jiebaptr;
}

SingleJieba::SingleJieba(){
    auto& conf_map = Configuration::createConfig()->getConfigMap(); 
    _jiebaptr = new Jieba(conf_map["dict_path"][0],
                          conf_map["model_path"][0],
                          conf_map["user_dict_path"][0],
                          conf_map["idfPath"][0],
                          conf_map["stopWordPath"][0]);
}

SingleJieba::~SingleJieba(){
    if(_jiebaptr != nullptr){
        delete _jiebaptr;
        _jiebaptr = nullptr;
    }
}